package com.juntuo.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;


@SuppressWarnings("deprecation")
public class HttpClientUtil {

    /**
     * 发送get请求，获取返回内容
     * @param url
     * @return
     * @throws Exception
     */
    public static String httpGet(String url) throws Exception{

        String result=""; //返回信息
        //创建一个httpGet请求
        HttpGet request=new HttpGet(url);
        //创建一个htt客户端
        @SuppressWarnings("resource")
        HttpClient httpClient=new DefaultHttpClient();
        //接受客户端发回的响应
        HttpResponse httpResponse=httpClient.execute(request);
        //获取返回状态
        int statusCode=httpResponse.getStatusLine().getStatusCode();
        String content=null;
        if(statusCode==HttpStatus.SC_OK){
            //得到客户段响应的实体内容
            HttpEntity responseHttpEntity=httpResponse.getEntity();
            content = EntityUtils.toString(responseHttpEntity, "utf-8");
        }
        //Log.d(TAG, statusCode+"");
        return content;
    }

}